#include "Texture.h"

Texture::Texture(unsigned int newheight, unsigned int newwidth): height(newheight), width(newwidth)
{
	Allocate();
}

Texture::Texture(const Texture& rhs)
{
	for(unsigned int i = 0; i < width; i++)
	{
		for(unsigned int j = 0; j < height; j++)
		{
			pixeldata[j*width+i] = rhs.GetPixel(i, j);
		}
	}
}

Texture::~Texture()
{
	delete pixeldata;
}

void Texture::Allocate()
{
	pixeldata = new Pixel[height * width];
}

unsigned int Texture::GetHeight() const
{
	return height;
}

unsigned int Texture::GetWidth() const
{
	return width;
}

const Pixel& Texture::GetPixel(unsigned int x, unsigned int y) const
{
	return pixeldata[y*width+x];
}

void Texture::SetColor(const Pixel& color)
{
	for(unsigned int i = 0; i < width; i++)
	{
		for(unsigned int j = 0; j < height; j++)
		{
			pixeldata[j*width+i] = color;
		}
	}
}

const Pixel& Texture::operator()(unsigned int x, unsigned int y) const
{
	return GetPixel(x, y);
}